package com.taotao.antlr4;

import com.taotao.antlr4.sql.RuleSetBaseVisitor;
import com.taotao.antlr4.sql.RuleSetParser;

public class MyRuleSetVisitor extends RuleSetBaseVisitor<Double> {

    @Override
    public Double visitMul(RuleSetParser.MulContext ctx) {
        double left = Double.parseDouble(ctx.NUMBER(0).getText());
        double right = Double.parseDouble(ctx.NUMBER(1).getText());
        return left * right;
    }

    @Override
    public Double visitDiv(RuleSetParser.DivContext ctx) {
        double left = Double.parseDouble(ctx.NUMBER(0).getText());
        double right = Double.parseDouble(ctx.NUMBER(1).getText());
        return left / right;
    }

    @Override
    public Double visitAdd(RuleSetParser.AddContext ctx) {
        double left = Double.parseDouble(ctx.NUMBER(0).getText());
        double right = Double.parseDouble(ctx.NUMBER(1).getText());
        return left + right;
    }

    @Override
    public Double visitSub(RuleSetParser.SubContext ctx) {
        double left = Double.parseDouble(ctx.NUMBER(0).getText());
        double right = Double.parseDouble(ctx.NUMBER(1).getText());
        return left - right;
    }
}